Skip to content

Conversation

Nielsbishere
Copy link
Contributor

@Nielsbishere Nielsbishere commented Jul 16, 2025

Currently, when resources are declared without explicit register bindings, DXC assigns them after GlobalDCE runs. This can lead to inconsistent register assignments across entry points (depending on optimizations), which causes mismatched resource IDs.

A common case is bindless-style includes, e.g. declaring multiple textures without explicit bindings but with spaces. In this situation, the generated binaries may not match across different entry points or when compiling as a library.

Solution

This PR introduces a new flag:

-consistent-bindings

When enabled, DXC will generate stable bindings by letting GlobalDCE eliminate only unused resources' symbols. Then, the bindings are generated and finally the unused resources are stripped again.

This ensures consistent register assignments across all entry points, whether compiling as individual shaders or as a library.

  • Resources are preserved until final binding assignment.
  • After assignment, unused bindings are stripped to avoid breaking optimization assumptions.
  • The behavior is similar to -flegacy-resource-reservation, but tailored for ensuring binding consistency.

Example

Command:

dxc -consistent-bindings -E main -T cs_6_0 myFile.hlsl

Shader:

Texture2D a;
Texture2D b;
RWTexture2D<float4> c;

[numthreads(1,1,1)]
void main() {
   c[0.xx] = b[0.xx];
}

[numthreads(1,1,1)]
void main2() {
   c[0.xx] = a[0.xx];
}

Generated bindings:

  • at0
  • bt1
  • cu0

Both main and main2 will consistently use the same bindings (b at t1, c at u0), regardless of entry point or library compilation.

Notes

…he IDxcRewriter, this will allow generating register ids for registers that don't fully define them.
…allow passing different rewriter flags. Also added support for cbuffer auto bindings.
…dxil lowering properly, it's similar to -flegacy-resource-reservation but distinct in some key ways: the option only works for reserved registers and we need it to work on any register that has been compiled out. We also don't necessarily need the register to stay at the end of DXIL generation, in fact we'd rather not. Because having the register present can cause unintended performance penalties (for example, I use this reflection to know what transitions to issue)
Copy link
Contributor

github-actions bot commented Sep 1, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@llvm-beanz
Copy link
Collaborator

@hekota & @bogner, please look over this. I'm not sure how this aligns with our work in Clang and how we want to handle bindings in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

2 participants